using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class PostUserVoteTotals : BasePage
{
    public override Acms.Bll.Role.Roles[] AllowedRoles
    {
        get { return new Acms.Bll.Role.Roles[] { Acms.Bll.Role.Roles.Developer, Acms.Bll.Role.Roles.ContentEditor, Acms.Bll.Role.Roles.ContentViewer, Acms.Bll.Role.Roles.UserGeneratedContentEditor }; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                postGuid = new Guid(Request.QueryString["PostGuid"]);
            }
            catch (FormatException)
            {
            }

            Acms.Bll.Post post = Acms.Bll.Post.GetByPostGuid(AcmsContext.SiteId, postGuid, null);
            if (post != null)
            {
                postHeader.SetPost(post);
                Title = string.Format("User Votes for '{0}'", post.DisplayName);
            }
        }
    }

    private Guid postGuid;
    protected override object SaveViewState()
    {
        ViewState["postGuid"] = postGuid;
        return base.SaveViewState();
    }

    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
        if (ViewState["postGuid"] is Guid)
            postGuid = (Guid)ViewState["postGuid"];
    }

    protected void dsVotes_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.UserPostVoteTotal> e)
    {
        List<Acms.Bll.UserPostVoteTotal> votes = Acms.Bll.UserPostVoteTotal.GetAllByPostGuid(postGuid);
        Acms.Bll.UserPostVoteTotal.Sort(votes, e.SortExpression);
        e.SetData(votes);
    }

}
